<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <button onclick="testGet()">GET请求</button>
      <button onclick="testPost()">POST请求</button>
      <button onclick="testPut()">PUT请求</button>
      <button onclick="testDelete()">DELETE请求</button>
    </div>

    <script src="https://cdn.bootcss.com/axios/0.19.0/axios.js"></script>

    <script>
      // 与Array.slice完全一样工作（即_start开始_end结束）
      function testGet() {
        axios
          .get("http://localhost:3000/posts", {
            params: {
              _start: 1,
              _end: 3,
              _limit: 2,
            },
          })
          .then((response) => {
            console.log(response.data);
          });
      }

      function testPost() {
        axios
          .post("http://localhost:3000/posts", {
            id: 4,
            title: "json-server4",
            author: "typicode4",
          })
          .then((response) => console.log(response.data));
      }

      function testPut() {
        axios
          .put("http://localhost:3000/posts/3", {
            title: "json-server...",
            author: "typicode...",
          })
          .then((response) => console.log(response.data));
      }

      function testDelete() {
        axios
          .delete("http://localhost:3000/posts/3")
          .then((response) => console.log(response.data));
      }
    </script>

    <!-- <script>
    function testGet() {
      // axios.get('http://localhost:3000/posts')
      // axios.get('http://localhost:3000/posts/1')
      axios.get('http://localhost:3000/posts?id=1')
        .then(response => {
          console.log('/posts get', response.data)
        })
    }

    function testPost() {
      axios.post('http://localhost:3000/posts', {"title": "json-server3", "author": "typicode3"})
        .then(response => {
          console.log('/posts post', response.data)
        })
    }

    function testPut() {
      axios.put('http://localhost:3000/posts/3', {"title": "json-server...", "author": "typicode..."})
        .then(response => {
          console.log('/posts put', response.data)
        })
    }

    function testDelete() {
      axios.delete('http://localhost:3000/posts/3')
        .then(response => {
          console.log('/posts delete', response.data)
        })
    }


  </script> -->
    <script></script>
  </body>
</html>
